package com.bjfu.utils;

import lombok.Getter;

import java.util.Arrays;

/**
 * 统一返回结果状态信息类
 *
 */
@Getter
public enum ResultCodeEnum {

    SUCCESS(200, "success"),
    USER_ISNULL(601, "userIsNull"),//用户名或者密码为空
    PASSWORD_ERROR(603, "passwordError"),//密码格式错误
    NOTLOGIN(604, "notLogin"),//未登录
    USERNAME_USED(605, "userForbidden"),//账号被禁用
    INSUFFICIENT_PERMISSIONS(606, "insufficientPermissions"),//权限不正确
    INSERT_FAILED(608, "InsertFailed"),//插入异常
    PASSWORD_DUPLICATED(609, "passwordDuplicated"),//修改密码与原密码重复
    // 新添加的错误码
    USER_EXISTS(607, "userExists"), // 用户已存在
    UPDATE_FAILED(610, "updateFailed"),//更新失败
    DELETE_FAILED(611, "deleteFailed"), //删除失败
    USER_NOT_FOUND(612,"userNotFound" ), //找不到用户
    JUDGE_REFUSED(613,"judgeRefused" ), //审核失败
    ACHIEVEMENT_NOT_FOUND(614,"achievementNotFound" ),
    ARTICLE_NOT_FOUND(615,"articleNotFound"  ),

    TEAM_NOT_FOUND(616,"teamNotFound" ),//找不到团队
    UPLOAD_FAILED(617, "uploadFailed"), //下载失败
    FILE_NOT_FOUND(618,"FileNotFound" ),//找不到该文件
    DOWNLOADFAILED(619,"downloadFailed" ), //下载失败
    DOWNLOADSUCCESS(620,"downloadSuccess" ), //下载成功
    PATH_NOT_FOUND(621,"pathNotFound" ),//该路径下无法找到文件资源
    NO_REPLY_FOUND(622,"replyNotFound" ),
    PERMISSION_NOT_FOUND(623, "permitNotFound"),//找不到回复内容
    QUESTION_NOT_FOUND(624,"questionNotFound" ),//找不到问题
    ACHIEVEMENT_STATUS_ERROR(625, "achievementStatusError"),//成果状态错误
    CANCELFAILED(626, "concelFailed"),//注销失败
    SENDFAILED(627,"sendFailed" ), //发送失败
    REPLY_ERROR(628, "replyError"),//回复失败
    USER_NOT_ACTIVE(629,"userNotActive" ),
    ERRORINFO_NOT_FOUND(630,"errorInfoNotFound");//没有找到审核拒绝信息

    //之后写也是按照这个格式继续往下列举状态码
    /*QUOTA_EXCEEDED(617, "quota exceeded"),
    ALREADY_EXISTS(618, "already exists"),
    NOT_FOUND(619, "not found");
    MENTORS_CODE_ALREADY_EXISTS(610, "mentors code already exists"),
    DIRECTIONS_ALREADY_EXISTS(611, "directions already exists"),
    IDENTITY_ALREADY_EXISTS(612, "identity already exists" ),
    REMOVE_FAILED(613, "remove operation failed"),
    INVALID_PARAM(614, "invalid param"),*/

    private Integer code;
    private String message;

    private ResultCodeEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 根据 code 获取枚举对象
     * @param code 返回码
     * @return 对应的枚举对象，如果没有匹配的返回 null
     */
    public static ResultCodeEnum fromCode(int code) {
        return Arrays.stream(values())
                .filter(resultCodeEnum -> resultCodeEnum.getCode() == code)
                .findFirst()
                .orElse(null);  // 如果没有匹配的，返回 null
    }
}

